﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VCN.App.DataTransferObjects;
using System.Data.SqlClient;

namespace VCN.App.DataAccessLayer
{
    public class ProductDAO:BasicDAO<Product>
    {
        public override bool insert(Product ip_product)
        {
            SqlConnection v_conn = BasicDAO<Product>.GetConnection();
            if (v_conn.State == ConnectionState.Closed)
            {
                v_conn.Open();
            }
            SqlCommand v_command = new SqlCommand("sp_tblProducts_Insert", v_conn);
            v_command.CommandType = CommandType.StoredProcedure;
            v_command.Parameters.Add("@Name", SqlDbType.NVarChar).Value = ip_product.Name;
            v_command.Parameters.Add("@Description", SqlDbType.NVarChar).Value = ip_product.Description;
            v_command.Parameters.Add("@Image", SqlDbType.VarChar).Value = ip_product.Image;
            v_command.Parameters.Add("@CateId", SqlDbType.Int).Value = ip_product.CateId;
            int v_rows = v_command.ExecuteNonQuery();
            v_conn.Close();
            if (v_rows > 0)
                return true;
            else
                return false;
        }

        public override System.Collections.Generic.List<Product> selectAll2List(Product ip_obj)
        {
            return null;
        }

        public override bool update(Product ip_obj)
        {
            return true;
        }
    }
}
